I'm running the command docker logs <container-id> | tail -10 and still, docker shows the entire log history. I know docker logs --tail 10 <container-id> is a valid command and serves the purpose. But, why doesn't the former command works as it does in case of a file?
If you want your everything your program writes to either stdout or stderr to go through the pipeline to tail, redirect stderr to stdout:
docker logs "$container_id" 2>&1 | tail -10
in case someone may want to tail -f docker logs
here you may try this:
docker logs -f --tail 0 "$container_id"